package com.jx.db137.controller;

import com.jx.db137.common.R;
import com.jx.db137.entity.Role;
import com.jx.db137.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jx
 * @version 1.0
 * @Description
 * @date 2024/12/24 11:51
 */
@CrossOrigin(origins = "*")
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("rolelist")
    public R rolelist(){
        return new R().addData("rolelist",roleService.list());
    }

    @PostMapping("updateRole")
    public R updateRole(@RequestBody Role role){
        return new R().addData("role",roleService.updateById(role));
    }
    @PostMapping("addRole")
    public R addRole(@RequestBody Role role){
        return new R().addData("role",roleService.insert(role));
    }



    //根据用户的id获取用户的角色
    @GetMapping("/selectRoleByUserId/{userid}")
    public R selectRoleByUserId(@PathVariable("userid") int userid){
        List<Role> roleList = roleService.selectRoleByUserId(userid);
        return new R().addData("roleList",roleList);
    }
}
